#include "gateway_server.hpp"
#include<gflags/gflags.h>

//日志类参数
DEFINE_bool(log_mod,false,"true为发布模式,false为调试模式");
DEFINE_string(log_file,"","发布模式下日志存储的文件");
DEFINE_int32(log_level,0,"要输出的日志等级");

DEFINE_int32(http_listen_port, 9000, "HTTP服务器监听端口");
DEFINE_int32(websocket_listen_port, 9001, "Websocket服务器监听端口");

DEFINE_string(registry_host, "http://127.0.0.1:2379", "服务注册中心地址");

DEFINE_string(base_service,"/service","服务查询的根目录");
DEFINE_string(file_service,"/service/file_service","服务查询的文件子服务目录");
DEFINE_string(user_service,"/service/user_service","服务查询的用户子服务目录");
DEFINE_string(speech_service,"/service/speech_service","服务查询的语音子服务目录");
DEFINE_string(message_service,"/service/message_service","服务查询的消息存储子服务目录");
DEFINE_string(transmit_service,"/service/transmit_service","服务查询的转发子服务目录");
DEFINE_string(friend_service,"/service/friend_service","服务查询的好友子服务目录");


DEFINE_string(redis_host,"127.0.0.1","redis访问地址");
DEFINE_int32(redis_port,6379,"redis服务器访问端口");
DEFINE_int32(redis_db,0,"redis默认库号");
DEFINE_bool(redis_keep_alive,true,"redis长期保活选项");


int main(int argc,char* argv[])
{
    google::ParseCommandLineFlags(&argc,&argv,true);
    zzy_mims::init_logger(FLAGS_log_mod,FLAGS_log_file,(spdlog::level::level_enum)FLAGS_log_level);
    
    //关闭brpc的默认日志输出
    logging::LoggingSettings logset;
    logset.logging_dest = logging::LoggingDestination::LOG_TO_NONE;
    logging::InitLogging(logset);

    zzy_mims::GatewayServerBuilder gsb; 
    gsb.make_redis_object(FLAGS_redis_host, FLAGS_redis_port, FLAGS_redis_db, FLAGS_redis_keep_alive);
    gsb.make_discover_object(FLAGS_registry_host, FLAGS_base_service, FLAGS_file_service,FLAGS_user_service,
    FLAGS_transmit_service,FLAGS_friend_service,FLAGS_message_service,FLAGS_speech_service);
    gsb.make_server_object(FLAGS_websocket_listen_port,FLAGS_http_listen_port);
    auto server = gsb.build();
    server->start();
    return 0;
}